<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>数组查找元素位置</title>
	</head>

	<body>
		<h4>题目描述</h4>
		<p>在数组 arr 中，查找值与 item 相等的元素出现的所有位置</p>
		<span>findAllOccurrences('abcdefabc'.split(''), 'a').sort()</span>
		<script type="text/javascript">
			function demo14(arr,value){
				var arrNew=[];
				arr.forEach(function(item,index){
					if(item==value){
						arrNew.push(index);
					}
				})
				return arrNew;
			}
			
			write(demo14(["a","b","c","d","e","f","a","b","c"],"a"));
			function write(text){
				document.write("<br /><span>答案:"+text+"</span>")
			}
//			function findAllOccurrences(arr,item){
//				var arr1=[]
//				arr.filter(function(el,index){
//					if(el==item){
//						arr1.push(index)
//					}
//					return arr1
//				})
//				return arr1
//			}
//			console.log(findAllOccurrences('abcdefabc'.split(''), 'a').sort())
		</script>
	</body>
	 
	 		

</html>